package systemInformation;

import java.util.ArrayList;
import java.util.List;

import features.SNMPException;
import features.SNMPSession;
import features.SNMPValue;

public class RouteInfo {

	private final static String IP_ROUTE_DESTINATION_OID = "1.3.6.1.2.1.4.21.1.1";
	private final static String IP_ROUTE_NEXT_HOP_OID = "1.3.6.1.2.1.4.21.1.7";
	private final static String IP_ROUTE_MASK_OID = "1.3.6.1.2.1.4.21.1.11";
	private final static String IP_ROUTE_TYPE_OID = "1.3.6.1.2.1.4.21.1.8";
	private final static String IP_ROUTE_AGE_OID = "1.3.6.1.2.1.4.21.1.10";

	private String destination = null;
	private String nextHop = null;
	private String mask = null;
	private String type = null;
	private String age = null;

	public static List<RouteInfo> fromSession(SNMPSession session)
			throws SNMPException {
		List<RouteInfo> routeTable = new ArrayList<RouteInfo>();

		List<SNMPValue> lstDest = session.getColumn(IP_ROUTE_DESTINATION_OID);
		List<SNMPValue> lstMask = session.getColumn(IP_ROUTE_MASK_OID);
		
		List<SNMPValue> lstNextHop = session.getColumn(IP_ROUTE_NEXT_HOP_OID);
		List<SNMPValue> lstType = session.getColumn(IP_ROUTE_TYPE_OID);
		List<SNMPValue> lstAge = session.getColumn(IP_ROUTE_AGE_OID);
		
		for (int i = 0; i < lstDest.size(); i++) {
			RouteInfo rowOfTable= new RouteInfo();
			
			rowOfTable.setDestination(lstDest.get(i).toString());
			rowOfTable.setMask(lstMask.get(i).toString());
			rowOfTable.setNextHop(lstNextHop.get(i).toString());
			rowOfTable.setType(lstType.get(i).toString());
			rowOfTable.setAge(lstAge.get(i).toString());
			
			routeTable.add(rowOfTable);
		}
	
		
		return routeTable;
	}

	public String getDestination() {
		return destination;
	}

	public void setDestination(String destination) {
		this.destination = destination;
	}

	public String getNextHop() {
		return nextHop;
	}

	public void setNextHop(String nextHop) {
		this.nextHop = nextHop;
	}

	public String getMask() {
		return mask;
	}

	public void setMask(String mask) {
		this.mask = mask;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAge() {
		return age;
	}

	public void setAge(String age) {
		this.age = age;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((age == null) ? 0 : age.hashCode());
		result = prime * result
				+ ((destination == null) ? 0 : destination.hashCode());
		result = prime * result + ((mask == null) ? 0 : mask.hashCode());
		result = prime * result + ((nextHop == null) ? 0 : nextHop.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final RouteInfo other = (RouteInfo) obj;
		if (age == null) {
			if (other.age != null)
				return false;
		} else if (!age.equals(other.age))
			return false;
		if (destination == null) {
			if (other.destination != null)
				return false;
		} else if (!destination.equals(other.destination))
			return false;
		if (mask == null) {
			if (other.mask != null)
				return false;
		} else if (!mask.equals(other.mask))
			return false;
		if (nextHop == null) {
			if (other.nextHop != null)
				return false;
		} else if (!nextHop.equals(other.nextHop))
			return false;
		if (type == null) {
			if (other.type != null)
				return false;
		} else if (!type.equals(other.type))
			return false;
		return true;
	}

}
